package com.doodle.common.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.wifi.WifiManager;
import android.util.Log;

public class WifiStateReceiver extends BroadcastReceiver {
    private final static String TAG = "dlna_wifi";
    private static DetailedState mLastState = DetailedState.IDLE;

    private void switchDlnaService(final boolean isStart) {
    }

    @Override
    public void onReceive(Context context, Intent intent) {   
        String action = intent.getAction();

        if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {

            NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            DetailedState state = info.getDetailedState();

            if (DetailedState.CONNECTED == state && mLastState != state) {  
                mLastState = state;
                //Log.d(TAG, "start service ................");
                Log.d(TAG, "stop service .................");
                switchDlnaService(false);
            }
            else if (DetailedState.DISCONNECTED == state && mLastState != state) {  
                mLastState = state;
                Log.d(TAG, "stop service .................");
                switchDlnaService(false);
            }
        }
    }  
}
